// service.js
const BASE_URL = 'https://vshow.jabbergo.com:6611'; // 后端接口地址

export default function service(options) {
  return new Promise((resolve, reject) => {
    const token = options.token || uni.getStorageSync('token') || 'ocHZSKuwn51xX7tivBffGdkZQuYov8GJDu/T8mvscMu6lrN4uYfzsBPPhZgymGb5';
    
    uni.request({
      url: BASE_URL + options.url,
      method: options.method || 'GET',
      data: options.data || {},
      header: {
        'content-type': 'application/json',
        'X-Authorization': token,
        ...(options.header || {})
      },
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data); // 仅返回 data 部分
        } else {
          reject(res); // 状态码不为 200
        }
      },
      fail: (err) => {
        reject(err); // 请求失败
      }
    });
  });
}
